package com.i360day.invoker.configuration;

import com.i360day.invoker.DefaultHttpInvokerClient;
import com.i360day.invoker.InvokerBasicConfiguration;
import com.i360day.invoker.NullRequestInterceptor;
import com.i360day.invoker.http.InvokerClient;
import com.i360day.invoker.interceptor.HttpInvokerRequestInterceptor;
import com.i360day.invoker.registry.RemoteScanDefinitionRegistryPostProcessor;
import com.i360day.invoker.request.HttpInvokerRequest;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liju.z
 */
@Configuration(proxyBeanMethods = false)
@ImportAutoConfiguration(InvokerBasicConfiguration.class)
public class HttpInvokerAutoConfiguration {
    /**
     * <p> @author liju.z <p>
     *
     * <p> @Description 创建默认请求拦截器 <p>
     *
     * <p> @Date  21:03 <p>
     *
     * <p> @return HttpInvokerRequestInterceptor <p>
     **/
    @Bean
    @ConditionalOnMissingBean
    public HttpInvokerRequestInterceptor simpleRequestInterceptor() {
        return new NullRequestInterceptor();
    }

    /**
     * <p> @author liju.z <p>
     *
     * <p> @Description 创建默认request <p>
     *
     * <p> @Date  21:04 <p>
     **/
    @Bean
    @ConditionalOnMissingBean
    public HttpInvokerRequest defaultHttpInvokerClient(InvokerClient invokerClient) {
        return new DefaultHttpInvokerClient(invokerClient);
    }

    @Bean
    @ConditionalOnMissingBean
    public RemoteScanDefinitionRegistryPostProcessor remoteBeanDefinitionRegistryPostProcessor(){
        return new RemoteScanDefinitionRegistryPostProcessor();
    }
}
